package triannon.client.util;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JCheckBox;
import javax.swing.JFrame;

@SuppressWarnings("serial")
public class DebuggerFrame extends JFrame {
	private DebugUtil debugUtil = DebugUtil.getInstance();

	public DebuggerFrame() {
		setLayout(new GridBagLayout());
		setAlwaysOnTop(true);
		GridBagConstraints constraints = new GridBagConstraints();
		constraints.gridx = 0;
		constraints.gridy = 0;
		constraints.anchor = GridBagConstraints.NORTHWEST;
		constraints.insets = new Insets(5, 5, 5, 5);

		JCheckBox cb = new JCheckBox(new ActionToggleGrid());
		cb.setSelected(debugUtil.isRenderGrid());

		add(cb, constraints);

		constraints.gridy++;

		cb = new JCheckBox(new ActionToggleBuildingQuad());
		cb.setSelected(debugUtil.isRenderBuildingDebugQuads());
		add(cb, constraints);

		constraints.gridy++;

		cb = new JCheckBox(new ActionToggleRenderUnitPaths());
		cb.setSelected(debugUtil.isRenderUnitPaths());
		add(cb, constraints);

		constraints.gridy++;

		cb = new JCheckBox(new ActionToggleRenderBlockedSectors());
		cb.setSelected(debugUtil.isRenderBlockedSectors());
		add(cb, constraints);

		pack();
	}

	class ActionToggleGrid extends AbstractAction {
		public ActionToggleGrid() {
			super("Render Grid");
		}

		@Override
		public void actionPerformed(ActionEvent e) {
			debugUtil.setRenderGrid(!debugUtil.isRenderGrid());
		}
	}

	class ActionToggleBuildingQuad extends AbstractAction {
		public ActionToggleBuildingQuad() {
			super("Render Building Quads");
		}

		@Override
		public void actionPerformed(ActionEvent e) {
			debugUtil.setRenderBuildingDebugQuads(!debugUtil
					.isRenderBuildingDebugQuads());
		}
	}

	class ActionToggleRenderUnitPaths extends AbstractAction {
		public ActionToggleRenderUnitPaths() {
			super("Render Unit Paths");
		}

		@Override
		public void actionPerformed(ActionEvent e) {
			debugUtil.setRenderUnitPaths(!debugUtil.isRenderUnitPaths());
		}
	}

	class ActionToggleRenderBlockedSectors extends AbstractAction {
		public ActionToggleRenderBlockedSectors() {
			super("Render Blocked Sectors");
		}

		@Override
		public void actionPerformed(ActionEvent e) {
			debugUtil.setRenderBlockedSectors(!debugUtil.isRenderBlockedSectors());
		}
	}

}
